package model

import "time"

type Comment struct {
	Cid      uint64    `gorm:"primary_key;auto_increment" json:"cid"`
	UserId   uint64    `gorm:"column:uid;not null" json:"uid" binding:"required" form:"uid"`
	Content  string    `gorm:"column:content;not null" json:"content" binding:"required" form:"content"`
	Pid      uint64    `gorm:"column:pid;not null" json:"pid" binding:"required" form:"pid"`
	CreateAt time.Time `gorm:"column:created_at" json:"create_at"`
	//关联字段
	User UserInfoModel `gorm:"foreignkey:UserId" binding:"-"`
}

// 根据comment找user
func (a *Comment) GetUserByComment() error {
	return DB.Self.Preload("User").First(&a).Error
}

// 添加评论
func (s *Comment) Create() error {
	return DB.Self.Create(&s).Error
}
